package com.hsbc.dev.teamo4.sms.sm.dao.impl;

import com.google.common.collect.Lists;
import com.hsbc.dev.teamo4.sms.common.utils.data.DBUtil;
import com.hsbc.dev.teamo4.sms.sm.dao.IAccountDao;
import com.hsbc.dev.teamo4.sms.sm.po.Account;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import java.util.List;

/**
 * @author:Cady
 * @version:
 * @Project: permission_manage
 * @Package: com.hsbc.dev.teamo4.sms.sm.dao.impl
 * @Description:
 * @Date date: 2018-07-27
 */
public class AccountDaoImpl implements IAccountDao {
    @Override
    public Account saveEntity(Account account) {
        String sql = "insert into sm_account values(?,?,?,?,?,?,?)";
        return (Account) DBUtil.saveEntity(sql,account,Lists.newArrayList("isEnable"));
    }

    @Override
    public Account updateEntity(Account account) {
        String sql = "update sm_account set username=?,password=?,updateId=?,updateTime=? where id=?";
        return (Account) DBUtil.updateEntity(sql,account,Lists.newArrayList("id","createId","isEnable","createTime"),account.getId());
    }

    @Override
    public int updateByIsEnable(String id,Boolean bool) {
        String sql = "update sm_account set isEnable=? where id=?";
        return DBUtil.updateByIsEnable(sql,id,bool);
    }

    @Override
    public Account queryById(String id) {
        String sql = "select * from sm_account where id='"+id+"'";
        BeanHandler beanHandler=new BeanHandler<>(Account.class);
        return (Account) DBUtil.queryById(sql,beanHandler);
    }

    @Override
    public List<Account> queryAllEntity() {
        String sql = "select * from sm_account";
        BeanListHandler beanListHandler=new BeanListHandler<>(Account.class);
        return (List<Account>) DBUtil.queryAllEntity(sql,beanListHandler);
    }


}
